import logging

try:
    file = open('./readme.md', 'r')
    for line in file.readlines():
        print(line, end='')
    print()
except IOError as e:
    logging.exception(e)
finally:
    # 文件使用完毕后必须关闭，因为文件对象会占用操作系统的资源，并且操作系统同一时间能打开的文件数量也是有限的
    if file:
        file.close()

with open('./readme.txt', 'r', encoding='utf-8', errors='ignore') as f:
    print(f.read())
    for line in f.readlines():
        print(line)
    print()

with open('./test.txt', 'a+') as f:
    f.write('hello!')
    # TODO 换行

# with open('./4.jpg', 'rb') as f:
#    print(f.read())
